package com.example.agriculture.service.impl;

import com.example.agriculture.dao.ShoppingCartDao;
import com.example.agriculture.entity.ShoppingCart;
import com.example.agriculture.service.ShoppingCartService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * (ShoppingCart)表服务实现类
 *
 * @author makejava
 * @since 2022-09-12 23:22:18
 */
@Service("shoppingCartService")
public class ShoppingCartServiceImpl implements ShoppingCartService {
    @Resource
    private ShoppingCartDao shoppingCartDao;

    /**
     * 通过ID查询单条数据
     *
     * @param shoppingId 主键
     * @return 实例对象
     */
    @Override
    public ShoppingCart queryById(Integer shoppingId) {
        return this.shoppingCartDao.queryById(shoppingId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<ShoppingCart> queryAllByLimit(int offset, int limit) {
        return this.shoppingCartDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param shoppingCart 实例对象
     * @return 实例对象
     */
    @Override
    public ShoppingCart insert(ShoppingCart shoppingCart) {
        this.shoppingCartDao.insert(shoppingCart);
        return shoppingCart;
    }

    /**
     * 修改数据
     *
     * @param shoppingCart 实例对象
     * @return 实例对象
     */
    @Override
    public ShoppingCart update(ShoppingCart shoppingCart) {
        this.shoppingCartDao.update(shoppingCart);
        return this.queryById(shoppingCart.getShoppingId());
    }

    /**
     * 通过主键删除数据
     *
     * @param shoppingId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer shoppingId) {
        return this.shoppingCartDao.deleteById(shoppingId) > 0;
    }

    @Override
    public List<ShoppingCart> SelectByUserId(int userid) {
        return shoppingCartDao.SelectByUserId(userid);
    }

    @Override
    public ShoppingCart insertAllInfor(Integer num, Integer productId, Integer producerId, int userid, Date date,Float totalPrice) {
        return shoppingCartDao.insertAllInfor(num,productId,producerId,userid,date,totalPrice);
    }

    @Override
    public boolean deleteByUserId(Integer userid) {
        return shoppingCartDao.deleteByUserId(userid)>0;
    }
}